<style>
  #bookIndent-back {
    padding: 20px 25px 25px 0;
  }

  #bookIndent-back .layui-treeSelect .ztree li a, .ztree li span {
    margin: 0 0 2px 3px !important;
  }
</style>
<div class="layui-fluid" id="bookIndent-back">
  <form class="layui-form" action="" lay-filter="bookIndent-back-form">
    <input type="hidden" name="id" data-th-value="${bookIndent.id}">
    <input type="hidden" name="bookname" data-th-value="${bookIndent.bookname}">
    <input type="hidden" name="pubid" data-th-value="${bookIndent.pubid}">
    <input type="hidden" name="number" data-th-value="${bookIndent.number}">
    <input type="hidden" name="bookmoney" data-th-value="${bookIndent.bookmoney}">
    <input type="hidden" name="username" data-th-value="${bookIndent.username}">
    <input type="hidden" name="type" data-th-value="${bookIndent.type}">
    <input type="hidden" name="flag" data-th-value="${bookIndent.flag}">
    <input type="hidden" name="status" data-th-value="${bookIndent.status}">
    <input type="hidden" name="backstatus" data-th-value="${bookIndent.backstatus}">
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">退书原因：</label>
      <div class="layui-input-block">
        <input type="text" name="backmessage" autocomplete="off" class="layui-input"
               lay-verify="required" placeholder="请输入您的 退书原因|损坏情况">
      </div>
    </div>
    <div class="layui-form-item febs-hide">
      <button class="layui-btn" lay-submit="" lay-filter="bookIndent-back-form-submit" id="submit"></button>
    </div>
  </form>
</div>

<script data-th-inline="javascript">
  layui.use(['febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        bookIndent = [[${bookIndent}]],
        $view = $('#bookIndent-back'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initbookIndentValue();

    function initbookIndentValue() {
      form.val("bookIndent-back-form", {
        "id": bookIndent.id,
        "bookname": bookIndent.bookname,
        "bookmoney": bookIndent.bookmoney,
        "type": bookIndent.type,
        "pubid": bookIndent.pubid,
        "username": bookIndent.username,
        "number": bookIndent.number,
        "flag": bookIndent.flag,
        "status": bookIndent.status,
        "backstatus": bookIndent.backstatus,
      });
    }

    form.on('submit(bookIndent-back-form-submit)', function (data) {
      data.field.backmessage === $('#backmessage').val;
      if (data.field.backstatus === "1") {
        febs.alert.warn("该书籍正在报损核实中。");
        return false;
      }
      if (data.field.backstatus === "2") {
        febs.alert.warn("该订单已经完成。");
        return false;
      }
      if (data.field.backstatus === "3") {
        febs.alert.warn("该书籍正在退书申请中。");
        return false;
      }
      if (data.field.flag === '0') {
        febs.post(ctx + 'bookIndent/backOne/', data.field, function () {
          layer.closeAll();
          febs.alert.success("尊敬的用户" + bookIndent.username + ' ，已成功为您取消订单。');
          $('#febs-bookIndent').find('#query').click();
        });
      } else {
        febs.post(ctx + 'bookIndent/backTwo/', data.field, function () {
          layer.closeAll();
          febs.alert.success("尊敬的用户" + bookIndent.username + ' ，退书请求已发送。');
          $('#febs-bookIndent').find('#query').click();
        });
      }
      return false;
    });
  });
</script>